using MediatR;
using System.ComponentModel.DataAnnotations;
using TaskProject.ErrorCode;

namespace TaskProject.Application.Command.Plan
{
    /// <summary>
    /// 新增生产计划命令
    /// </summary>
    public class AddProductionPlanCommand : IRequest<APIResult<int>>
    {
        /// <summary>
        /// 计划主题
        /// </summary>
        [Required(ErrorMessage = "计划主题不能为空")]
        [MaxLength(200, ErrorMessage = "计划主题长度不能超过200个字符")]
        public string PlanSubject { get; set; }

        /// <summary>
        /// 计划单号
        /// </summary>
        [Required(ErrorMessage = "计划单号不能为空")]
        [MaxLength(50, ErrorMessage = "计划单号长度不能超过50个字符")]
        public string PlanOrderNumber { get; set; }

        /// <summary>
        /// 单据日期
        /// </summary>
        public DateTime? DocumentDate { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [MaxLength(500, ErrorMessage = "备注长度不能超过500个字符")]
        public string? Remarks { get; set; }

        /// <summary>
        /// 销售订单号（可选）
        /// </summary>
        [MaxLength(50, ErrorMessage = "销售订单号长度不能超过50个字符")]
        public string? SalesOrderNumber { get; set; }

        /// <summary>
        /// 关联项目名称
        /// </summary>
        [MaxLength(100, ErrorMessage = "关联项目名称长度不能超过100个字符")]
        public string? RelatedProjectName { get; set; }

        /// <summary>
        /// 预计开始日期
        /// </summary>
        public DateTime? ExpectedStartDate { get; set; }

        /// <summary>
        /// 预计完成日期
        /// </summary>
        public DateTime? ExpectedEndDate { get; set; }

        /// <summary>
        /// 生产线
        /// </summary>
        [MaxLength(100, ErrorMessage = "生产线长度不能超过100个字符")]
        public string? ProductionLine { get; set; }

        /// <summary>
        /// 优先级（1-低，2-中，3-高，4-紧急）
        /// </summary>
        [Range(1, 4, ErrorMessage = "优先级必须在1-4之间")]
        public int Priority { get; set; } = 2;

        /// <summary>
        /// 生产物品列表
        /// </summary>
        [Required(ErrorMessage = "生产物品不能为空")]
        public List<ProductionPlanItemInfo> ProductionItems { get; set; } = new List<ProductionPlanItemInfo>();

        /// <summary>
        /// 附件列表
        /// </summary>
        public List<ProductionPlanAttachmentInfo> Attachments { get; set; } = new List<ProductionPlanAttachmentInfo>();
    }

    /// <summary>
    /// 生产计划物品信息
    /// </summary>
    public class ProductionPlanItemInfo
    {
        /// <summary>
        /// 物品编号
        /// </summary>
        [Required(ErrorMessage = "物品编号不能为空")]
        [MaxLength(50, ErrorMessage = "物品编号长度不能超过50个字符")]
        public string ItemNumber { get; set; }

        /// <summary>
        /// 物品名称
        /// </summary>
        [Required(ErrorMessage = "物品名称不能为空")]
        [MaxLength(200, ErrorMessage = "物品名称长度不能超过200个字符")]
        public string ItemName { get; set; }

        /// <summary>
        /// 规格型号
        /// </summary>
        [MaxLength(100, ErrorMessage = "规格型号长度不能超过100个字符")]
        public string? SpecificationModel { get; set; }

        /// <summary>
        /// 单位
        /// </summary>
        [MaxLength(20, ErrorMessage = "单位长度不能超过20个字符")]
        public string? Unit { get; set; }

        /// <summary>
        /// 物品类别
        /// </summary>
        [MaxLength(50, ErrorMessage = "物品类别长度不能超过50个字符")]
        public string? ItemCategory { get; set; }

        /// <summary>
        /// 物品分类
        /// </summary>
        [MaxLength(50, ErrorMessage = "物品分类长度不能超过50个字符")]
        public string? ItemClassification { get; set; }

        /// <summary>
        /// 品牌
        /// </summary>
        [MaxLength(100, ErrorMessage = "品牌长度不能超过100个字符")]
        public string? Brand { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        [Required(ErrorMessage = "数量不能为空")]
        [Range(1, int.MaxValue, ErrorMessage = "数量必须大于0")]
        public int Quantity { get; set; }

        /// <summary>
        /// 排序序号
        /// </summary>
        public int SortOrder { get; set; }
    }

    /// <summary>
    /// 生产计划附件信息
    /// </summary>
    public class ProductionPlanAttachmentInfo
    {
        /// <summary>
        /// 文件名
        /// </summary>
        [Required(ErrorMessage = "文件名不能为空")]
        [MaxLength(200, ErrorMessage = "文件名长度不能超过200个字符")]
        public string FileName { get; set; }

        /// <summary>
        /// 文件大小（字节）
        /// </summary>
        [Range(1, long.MaxValue, ErrorMessage = "文件大小必须大于0")]
        public long FileSize { get; set; }

        /// <summary>
        /// 文件路径
        /// </summary>
        [Required(ErrorMessage = "文件路径不能为空")]
        [MaxLength(500, ErrorMessage = "文件路径长度不能超过500个字符")]
        public string FilePath { get; set; }

        /// <summary>
        /// 文件类型
        /// </summary>
        [MaxLength(100, ErrorMessage = "文件类型长度不能超过100个字符")]
        public string? FileType { get; set; }
    }
} 